package com.xmfh.wemedia.service.impl;

import com.xmfh.wemedia.model.DdMicro;
import com.xmfh.wemedia.mapper.DdMicroMapper;
import com.xmfh.wemedia.model.DdSubMicro;
import com.xmfh.wemedia.service.IDdMicroService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmfh.wemedia.service.IDdSubMicroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 微头条表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2022-04-03
 */
@Service
public class DdMicroServiceImpl extends ServiceImpl<DdMicroMapper, DdMicro> implements IDdMicroService {
    @Autowired
    private DdMicroMapper microMapper;

    @Override
    public int addDynamic(DdMicro micro) {

        micro.setFabulous(0);
        micro.setComment(0);
        micro.setViews(0);
        micro.setHot(0);
        micro.setUserId(1);
        micro.setCreateTime(LocalDateTime.now());
        return microMapper.insertDynamic(micro);
    }

    @Override
    public List<DdMicro> getByUserID(Integer pageNum, Integer pageSize,Integer userId) {
        pageNum = (pageNum - 1) * 10;
        return microMapper.getByUserID(pageNum, pageSize,userId);
    }

    @Override
    public int selectCount(Integer userId) {
        int count = microMapper.selectCount(userId);
        if (count % 10 > 0) {
            return count / 10 + 1;
        } else {
            return count / 10;
        }
    }
}
